Ext.define('AM.controller.Customers', {
	extend : 'Ext.app.Controller',
	stores : [ 'Customers' ],
	models : [ 'Customer' ],
	views : [ 'customer.Edit', 'customer.List' ],
	init : function() {
		this.control({
			'viewport > customerlist dataview' : {
				itemdblclick : this.edit
			},
			'customeredit button[action=save]' : {
				click : this.update
			}
		});
	},

	edit : function(grid, record) {
		var edit = Ext.create('AM.view.customer.Edit').show();

		edit.down('form').loadRecord(record);
	},

	update : function(button) {
		var win = button.up('window'), form = win.down('form'), record = form
				.getRecord(), values = form.getValues();

		record.set(values);
		win.close();
		this.getCustomersStore().sync();
	}
});
